//
//  DepositViewController.swift
//  cxd4iphone
//
//  Created by hexy on 12/3/15.
//  Copyright © 2015 hexy. All rights reserved.
//

import UIKit

private struct kConstraints {
    
    static let headerHeight: CGFloat = xx_height(250)
    static let headerRect: CGRect    = CGRectMake(0, 0, xx_screenWidth(), kConstraints.headerHeight)
    static let footerHeight: CGFloat = xx_screenHeight() - kConstraints.headerHeight - 64 - 49
    static let footerRect: CGRect    = CGRectMake(0, 0, xx_screenWidth(), kConstraints.footerHeight)
}

class DepositViewController: BaseTableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    override func makeTableView() {
        
        tableView.tableHeaderView = depositView
        
        depositView.nextBtn.rac_signalForControlEvents(.TouchUpInside).subscribeNext { (_) -> Void in
            
            xx_print(self.depositView.textField.text)
            
            if let money = self.depositView.textField.text {
                
                
                YPRequestViewModel.shared.recharge(money).subscribeError({ (error) -> Void in
                    
                        xx_showError(error)
                    
                    }, completed: { () -> Void in
                        
                        xx_print(YPRequestViewModel.shared.html)
                        
                        let vc = WebViewController(title: "充值", htmlStr: YPRequestViewModel.shared.html)
                        self.navigationController?.pushViewController(vc, animated: true)
                })
            }
           
//            YPRequestViewModel.shared.bindBankCard().subscribeError({ (error) -> Void in
//                
//                    xx_print(error)
//                }, completed: { () -> Void in
//                    
//                    let vc = WebViewController(title: "绑卡", htmlStr: YPRequestViewModel.shared.html)
//                    
//                    self.navigationController?.pushViewController(vc, animated: true)
//            })
        }
    }
    
    lazy var depositView = DepositView(frame: kConstraints.headerRect)
}

